#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) JoinQuant Development Team
# Author: Huayong Kuang <kuanghuayong@joinquant.com>

from multiprocessing.pool import Pool


def worker(a, b=0):
    # if b == 3:
        # raise ValueError('test error')
    return a + b


def handle_error(ex):
    print("===> Error:", ex)


if __name__ == "__main__":
    pool = Pool(4)
    rets = []
    for i in range(4):
        ret = pool.apply_async(worker, (i *10,), {'b': i}, error_callback=handle_error)
        rets.append(ret)
    print([ret.get() for ret in rets])
    pool.close()
    pool.join()
